/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
var countSubarrays = function (nums, k) {
  let arr = []
  let count=0
  let left=0,right,mid
  while(left<nums.length){
    for(right=left+1;right<nums.length+1;right++){
      arr = nums.slice(left,right)
      mid = arr.length%2==0?arr.length/2-1:Math.floor(arr.length/2)
      if(arr.sort((a,b)=>a-b)[mid]==k){
       count++
      }
      
    }
    left++
   

  }
  return count
}

countSubarrays([2,3,1],3)
